<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <script src="/q.js"></script>
    <script>
      q.get('/hello?hello=1')
      .then(function(response) {
        console.log(response.data);
      })
      .catch(function(err){
        console.log(err);
      });
      // 添加通用拦截器
      q.default.common.preInterceptor.push({
        fulfill: function(request) {
          request.setData('me', '1');
          return request;
        }
      });
      // 添加拦截器
      q.preInterceptor.add(function(request){
        request.setData('x', '2 ');
        return request;
      }, function(err) {
        return Promise.reject(err);
      });
      q.postInterceptor.add(function(response){
        console.log(response.statusText);
        return response;
      }, function(err) {
        return Promise.reject(err);
      });
      q.get('/hello?text=3', {
        data: {
          text: 1
        }
      })
      .then(function(response){
        console.log(response.data);
      })
      .catch(function(err){
        console.log(err);
      });

      const param = new URLSearchParams();
      param.append('you', 'hello');
      q.get('/me',{
        data: param
      })
      .then(function(response) {
        console.log(response.data);
      });

      q.jsonp('/jsonp')
      .then(function(response) {
        alert(response.data);
      });
    </script>
  </body>
</html>